package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = CheckItemService.class)//注意此处添加class,目的是指定实现的iterface类
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper checkItemMapper;

    @Override
    public void add(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Page<CheckItem> page = null;
        if (queryPageBean.getQueryString() == null) {
            PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
            //如果点击不是第一页时,再进行输入查询条件,当前页不是第一页,(这种情况,在查询按钮的点击方法处,将当前页复位i1,这不对
            // )
            // 显示会有问题.还有就是空格问题
            page = checkItemMapper.findPage(queryPageBean.getQueryString());
        }else{
            queryPageBean.setCurrentPage(1);
            PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
            page = checkItemMapper.findPage(queryPageBean.getQueryString());
        }
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public CheckItem findById(Integer id) {
        CheckItem cki = checkItemMapper.findById(id);
        return cki;
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemMapper.edit(checkItem);
    }

    @Override
    public List<CheckItem> findCheckitem() {
        List<CheckItem> list = checkItemMapper.findCheckitem();
        return list;
    }
}
